﻿using MTOM_Library;
using MTOM_Library.MtomWebService;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Data.OleDb;
using System.IO;
using System.Linq;
using System.Media;
using System.Net;
using System.Threading;
using System.Web.UI;
using System.Windows.Forms;
using ToolUtil;
using UploadWinClient;
using zyconfig;
using zymarc;

namespace zymain
{
    public partial class FrmGcwh : Form
    {
        public BindingSource BookData;
        public DataTable xndt = new DataTable();
        public BindingSource CfData;
        public BindingSource DcData;
        private string mTxt;
        private string mIso;
        private string mainKay;
        private int kjm;
        private int gjm;
        private string uid;
        private string marc = string.Empty;
        private bool flag = false;
        private string ydl;
        private string ydj;
        private List<int> kid = new List<int>();
        private int xzid=0;
        private List<string> gcd = new List<string>();
        private string xzgcd;
        private int usType = 2;
        public static MTOMWse WebService;
        private bool ftpFull = false;
        private UploadFiles up;
        public FrmGcwh()
        {
            InitializeComponent();
            //this.DgvCombobox();
            this.dataGridDc.DataError += delegate (object sender, DataGridViewDataErrorEventArgs e) { };
        }
       
        private void frnMain_shown(object sender, EventArgs e)
        {
            this.baseSearch1.AddConfig(0);
        }
        private void baseSearch1_BtnScarchClick(object sender, EventArgs e)
        {
            this.Invalidate();
            this.kjm = this.baseSearch1._kjm;
            this.Cursor = Cursors.WaitCursor;
            string sql = this.baseSearch1.Sql;
            this.BookData = new BindingSource();
            DataTable dt = new DataTable();
            //DataTable d1 = new DataTable();
            using (DbOperHandler _open = new Common().Doh())
            {
                if (_open.dbType.ToString().Equals("ORACLE") || _open.odbType.ToString().Equals("ORACLE"))
                    flag = true;
               _open.Reset();
                _open.SqlCmd = sql;
                //Console.WriteLine(sql);
                dt = _open.GetDataTable();
                //d1 = DTable.TrimValueForOutPut(dt);
                var dataRows = dt.AsEnumerable();
                foreach (var row in dataRows)
                {
                    var cellList = row.ItemArray.ToList();
                    row.ItemArray = cellList.Select(x => x.ToString().Trim()).ToArray();
                }
                this.dataGridBook.Columns.Clear();
                this.dataGridBook.AutoGenerateColumns = true;
                this.BookData.DataSource = dt;
                this.binNavBook.BindingSource = this.BookData;
                this.BookData.PositionChanged += new EventHandler(this.BookData_PositionChanged);
                this.dataGridBook.DataSource = this.BookData;
                this.dataGridBook.AutoResizeColumns(DataGridViewAutoSizeColumnsMode.AllCells);//宽度自适应
                //this.dataGridBook.Columns.Remove(this.dataGridBook.Columns[this.dataGridBook.ColumnCount-1]);
                if (this.BookData.Count == 0)
                {
                    MessageBox.Show("未检索到任何记录");
                    this.saveBtn.Enabled = false;
                    this.delBtn.Enabled = false;
                    this.cisoBtn.Enabled = false;
                    this.upfsBtn.Enabled = false;
                }
                else
                {
                    this.BookData_PositionChanged(sender, e);
                    this.saveBtn.Enabled = true;
                    this.delBtn.Enabled = true;
                    this.cisoBtn.Enabled = true;
                    this.upfsBtn.Enabled = true;
                }
            }
            this.Cursor = Cursors.Default;
        }
        private void BookData_PositionChanged(object sender, EventArgs e)
        {
            DataRowView current = this.BookData.Current as DataRowView;
            mainKay = current["主键码"].ToString().Trim();
            using (DbOperHandler _open = new Common().Doh())
            {
                if (flag)
                {
                    this.flag = true;
                    _open.Reset();
                    _open.ConditionExpress = " 主键码=" + mainKay;
                    marc = _open.GetField("MARC_DATA", "marc1").ToString();
                    if(string.IsNullOrEmpty(marc))
                        marc = _open.GetField("MARC_DATA", "marc2").ToString();
                    if (string.IsNullOrEmpty(marc))
                        marc = _open.GetField("MARC_DATA", "marc3").ToString();
                }
                else
                {
                    _open.Reset();
                    _open.ConditionExpress = " 主键码=" + mainKay;
                    marc = _open.GetField("馆藏书目库", "marc").ToString();
                }
                _open.Reset();
                _open.ConditionExpress = " 库键码=" + this.kjm;
                int mlx = Convert.ToInt32(_open.GetField("书目数据库定义", "MARC类型").ToString().Trim());
                //Console.WriteLine("marc:" + marc);
                if (!string.IsNullOrEmpty(marc))
                {
                    this.marcGrid1.key = mainKay;
                    this.marcGrid1.kjm = this.kjm.ToString();
                    this.marcGrid1.MarcType = mlx;
                    try
                    {
                        MarcConvert convert = new MarcConvert();
                        convert.ISOData = marc;
                        if (marc.Split('\x001e')[0].Length < 25)
                        {
                            convert.MarcText = marc;
                            convert.SetISOStr();
                            convert.SetISOtoMarc();
                        }
                        else
                        {
                            convert.SetISOtoMarc();
                        }
                        this.marcGrid1.MarcText = convert.MarcText;
                        this.mTxt= convert.MarcText; 
                        this.marcGrid1.SetGridView();
                    }
                    catch { }
                }
                _open.Reset();
                _open.SqlCmd = "select c.状态,c.订单号,c.预订日期,c.订购册数,c.订购单价,c.订购金额,c.币种,f.发行商,j.经费名称,c.批次号,c.册数,c.单价,c.金额,c.验收日期,c.采购员,c.登录号,c.验收员,c.编目日期,c.编目员,c.典藏员,c.入藏日期,c.子键码 from 采购库 c left join 发行商库 f on c.发行商键码=f.键码 left join 采购经费库 j on j.键码=c.经费来源键码 where c.主键码=" + mainKay + " order by 预订日期";
                DataTable dcg = _open.GetDataTable();
                for (int i = 0; i < dcg.Rows.Count; i++)
                {
                    if (dcg.Rows[i]["状态"].ToString().Trim().Equals("C"))
                    {
                        if (string.IsNullOrEmpty(dcg.Rows[i]["登录号"].ToString().Trim()))
                            dcg.Rows[i]["状态"] = "采购"; 
                        else
                            dcg.Rows[i]["状态"] = "验收";
                    }
                    if (dcg.Rows[i]["状态"].ToString().Trim().Equals("G"))
                        dcg.Rows[i]["状态"] = "入藏";
                }
                this.CfData = new BindingSource();
                //this.dataGridCg.AutoGenerateColumns = false;
                this.CfData.DataSource = dcg;
                dataGridCg.DataSource = this.CfData;
                this.CfData.PositionChanged += new EventHandler(this.CfData_PositionChanged);
                this.dataGridCg.AutoResizeColumns(DataGridViewAutoSizeColumnsMode.AllCells);//宽度自适应
                if (this.CfData.Count > 0)
                {
                    this.dataGridCg.Columns[this.dataGridCg.Columns.Count-1].Visible = false;
                    this.dataGridCg.CurrentCell = this.dataGridCg.Rows[this.dataGridCg.Rows.Count - 1].Cells[0];
                    //模拟点击事件（点击选中行）
                    this.dataGridCg_CellClick(dataGridCg, new DataGridViewCellEventArgs(dataGridCg.SelectedCells[0].ColumnIndex, dataGridCg.SelectedCells[0].RowIndex));
                    this.CfData_PositionChanged(sender, e);
                }
                _open.Reset();
                _open.ConditionExpress = "主键码=" + mainKay;
                //if (_open.Exist("Disk_文件信息表"))
                //    ShowMessageBox.ShowMessageBoxTimeout("111", "", MessageBoxButtons.OK, 2000);
                _open.Reset();
                _open.SqlCmd = "select d.登录号,d.条形码,RTRIM(LTRIM(c.部门名称)) AS 馆藏地点,RTRIM(LTRIM(x.库室名称)) AS 虚拟库室,d.状态,d.备注,d.处理日期,d.操作员,d.清点状态,d.清点日期,d.清点员,RTRIM(LTRIM(d.索书号)) AS 索书号,d.子键码  from 馆藏典藏库 d left join 虚拟库室 x on d.虚拟库室=x.虚拟库室 left join 馆藏地址定义 c on c.馆藏地址=d.馆藏地址 where d.状态!='L' and d.主键码=" + mainKay+" order by d.登录号";
                DataTable dck = _open.GetDataTable();
                for (int i = 0; i < dck.Rows.Count; i++)
                {
                    if (dck.Rows[i]["状态"].ToString().Trim().Equals("C"))
                    {
                       dck.Rows[i]["状态"] = "采购";
                    }
                    if (dck.Rows[i]["状态"].ToString().Trim().Equals("G"))
                        dck.Rows[i]["状态"] = "入藏";
                    if (dck.Rows[i]["状态"].ToString().Trim().Equals("L"))
                        dck.Rows[i]["状态"] = "其他";
                }
                this.DcData = new BindingSource();
                this.dataGridDc.AutoGenerateColumns = false;
                this.DcData.DataSource = dck;
                dataGridDc.DataSource = this.DcData;
                this.DgvKbox();
                this.DgvGcbox();
            }
        }
        private void DgvKbox()
        {
            using (DbOperHandler _open = new Common().Doh())
            {
                _open.Reset();
                _open.SqlCmd = "select 虚拟库室 as id,RTRIM(LTRIM(库室名称)) AS 虚拟库室 from 虚拟库室 where 虚拟库室>0 order by 虚拟库室";
                DataTable dt = _open.GetDataTable();
                foreach(DataRow dRow in dt.Rows)
                {
                    kid.Add(Convert.ToInt32(dRow["id"]));
                }
                this.xnkss.DataSource = dt;
                this.xnkss.DisplayMember = "虚拟库室";
                this.xnkss.ValueMember = "虚拟库室";
                this.xnkss.DataPropertyName = "虚拟库室";
                this.xnkss.ValueType = typeof(Int32);
            }
        }

        private void CfData_PositionChanged(object sender, EventArgs e)
        {
            DataRowView current = this.CfData.Current as DataRowView;
            if (current.Row != null)
            {
                this.newBtn.Enabled = true;
                string dlh = current["登录号"].ToString().Trim();
                dlh = StringUtil.ToDBC(dlh);
                this.dqdlhTxt.Text = dlh;
                this.ydl = dlh;
                string dj = current["单价"].ToString().Trim();
                if (string.IsNullOrEmpty(dj))
                    dj = current["订购单价"].ToString().Trim();
                this.ydj = dj;
                this.dqdjTxt.Text = dj;
                string cs = current["册数"].ToString().Trim();
                if (string.IsNullOrEmpty(cs))
                    cs = current["订购册数"].ToString().Trim();
                this.dqcsTxt.Text = cs;
                string je = current["金额"].ToString().Trim();
                if (string.IsNullOrEmpty(je))
                    je = current["订购金额"].ToString().Trim();
                this.dqjeTxt.Text = je;
            }
            else
                this.newBtn.Enabled = false;
        }
        private void exitBtn_Click(object sender, EventArgs e)
        {
            base.Close();
        }

        private void saveBtn_Click(object sender, EventArgs e)
        {
            this.marcGrid1.GetGridView();
            if (!this.marcGrid1.Nmarc.Equals(this.marcGrid1.MarcText))
                this.marcGrid1.saveMarc();
        }

        private void FrmGcwh_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.S && e.Control)//e.Control是判断用户是否按下ctrl键 
            {
                this.saveBtn_Click(sender, e);
            }
            if (e.KeyCode == Keys.Escape)//e.Control是判断用户是否按下ctrl键 
            {
                base.Close();
            }
        }

        private void delBtn_Click(object sender, EventArgs e)
        {
            if (MessageBox.Show("删除馆藏记录将无法恢复，是否继续？", "提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Question, MessageBoxDefaultButton.Button2) == DialogResult.OK)
            {
                try
                {
                    using (DbOperHandler _open = new Common().Doh())
                    {
                        _open.Reset();
                        _open.ConditionExpress = "主键码=" + this.mainKay;
                        string tm = _open.GetField("馆藏书目库", "题名").ToString();
                        if (!flag)
                            marc = _open.GetField("馆藏书目库", "marc").ToString();
                        else
                            tm = _open.GetField("馆藏书目库", "题名2").ToString();
                        int s = _open.Delete("馆藏书目库");
                        if (s > 0)
                        {
                            _open.Reset();
                            _open.AddFieldItem("主键码", mainKay);
                            _open.AddFieldItem("库键码", kjm);
                            _open.AddFieldItem("题名", tm);
                            _open.AddFieldItem("marc", this.marc);
                            _open.AddFieldItem("操作员", Convert.ToInt32(this.uid));
                            _open.AddFieldItem("被删除日期", DateTime.Now);
                            _open.Insert("删除记录日志库");
                            ShowMessageBox.ShowMessageBoxTimeout("删除成功！", "提示", MessageBoxButtons.OK, 2000);
                            this.baseSearch1_BtnScarchClick(sender, e);
                        }
                    }
                }catch(Exception ex)
                {
                    ShowMessageBox.ShowMessageBoxTimeout(ex.Message, "出错啦！", MessageBoxButtons.OK, 2000);
                }
            }
        }

        private void FrmGcwh_Load(object sender, EventArgs e)
        {
            WebService = new MTOMWse();
            string formName = "FrmTool";
            Form fr = System.Windows.Forms.Application.OpenForms[formName];
            if (fr != null)
            {
                FrmTool f1 = (FrmTool)fr;
                //取到Form1的值是1
                this.uid = f1.UserID;
                this.gjm = f1.Gjm;
            }
            this.taskPanel1.RemoveItemsWhenFinished = true;
            this.taskPanel1.RemoveItemsOnError = false;
            this.taskPanel1.AutoSizeForm = false;
            this.MarcRadio();
            this.workerGetFileList.RunWorkerAsync();
            this.workerFtp.RunWorkerAsync();
            this.dudMaxThreads_ValueChanged(sender, e);
        }
        private bool AuthenticateWebService()
        {
            if ((WebService.CookieContainer != null) && (WebService.CookieContainer.Count > 0))
            {
                return true;
            }
            try
            {
                string str = string.Format("?Username={0}&Password={1}", this.txtUsername.Text, this.txtPassword.Text);
                //Console.WriteLine(WebService.Url.Replace("MTOM.asmx", "") + "Login.aspx" + str);
                HttpWebRequest request = WebRequest.Create(WebService.Url.Replace("MTOM.asmx", "") + "Login.aspx" + str) as HttpWebRequest;
                request.CookieContainer = new CookieContainer();
                HttpWebResponse response = (HttpWebResponse)request.GetResponse();
                WebService.CookieContainer = request.CookieContainer;
                return (response.Cookies.Count > 0);
            } 
            catch (WebException ex)
            {
                //Console.WriteLine(ex.Message);
                return false;
            }
        }
        private void MarcRadio()
        {
            foreach (System.Windows.Forms.Control c in usPanel.Controls)
            {
                if (c is RadioButton)
                {
                    if (((RadioButton)c).Checked)
                    {
                        usType = ((RadioButton)c).TabIndex;
                    }
                }
            }
        }
        private void newBtn_Click(object sender, EventArgs e)
        {
            using (DbOperHandler _open = new Common().Doh())
            {
                DataRowView current = this.CfData.Current as DataRowView;
                string zjm = current["子键码"].ToString().Trim();
                _open.Reset();
                _open.ConditionExpress = "主键码=" + mainKay + " and 子键码=" + zjm;
                int fxsjm = Convert.ToInt32(_open.GetField("采购库", "发行商键码").ToString().Trim());
                int jfjm = Convert.ToInt32(_open.GetField("采购库", "经费来源键码").ToString().Trim());
                double dj =Convert.ToDouble(_open.GetField("采购库", "订购单价").ToString().Trim());
                string ddh = _open.GetField("采购库", "订单号").ToString().Trim();
                List<int> zjmList = new List<int>();
                _open.Reset();
                _open.SqlCmd = " select 子键码 from 采购库 order by 子键码";
                DataTable dcg = _open.GetDataTable();
                if (dcg.Rows.Count > 0)
                {
                    for (int i = 0; i < dcg.Rows.Count; i++)
                    {
                        //Console.WriteLine(dcg.Rows[i]["子键码"].ToString());
                        zjmList.Add(Convert.ToInt32(dcg.Rows[i]["子键码"].ToString()));
                    }
                }
                int czjm = StringUtil.GetNextNumber(zjmList);
                _open.Reset();
                _open.AddFieldItem("馆键码", gjm);
                _open.AddFieldItem("库键码", kjm);
                _open.AddFieldItem("子键码", czjm);
                _open.AddFieldItem("发行商键码", fxsjm);
                _open.AddFieldItem("经费来源键码", jfjm);
                _open.AddFieldItem("主键码", mainKay);
                _open.AddFieldItem("订购单价", dj);
                _open.AddFieldItem("预订日期", DateTime.Now);
                _open.AddFieldItem("采购员", this.uid);
                _open.AddFieldItem("状态", "C");
                _open.AddFieldItem("订单号", ddh);
                _open.Insert("采购库");
                this.BookData_PositionChanged(sender, e);
            }
            //this.sBtn.Enabled = true;
            //this.cxBtn.Enabled = true;
        }

        private void cxBtn_Click(object sender, EventArgs e)
        {
            this.sBtn.Enabled = false;
            this.dqdlhTxt.Text = ydl;
        }

        private void dlh_MouseLeave(object sender, EventArgs e)
        {
            string xdlh = StringUtil.ToDBC(this.dqdlhTxt.Text.Trim());
            //判断用户输入不为空，并且新的输入值不等于定义的全局变量
            if (!xdlh.Equals(ydl))
            {
                this.cxBtn.Enabled = true;
                this.sBtn.Enabled = true;
            }
            else
            {
                this.cxBtn.Enabled = false;
                this.sBtn.Enabled = false;
            }
        }
        private void sBtn_Click(object sender, EventArgs e)
        {
            this.dlKetPress();
            this.BookData_PositionChanged(sender, e);
        }
        private void dlh_KeyPress(object sender, KeyPressEventArgs e)
        {
            if (e.KeyChar == '\r')
            {
                this.dlKetPress();
                this.BookData_PositionChanged(sender, e);
            }
        }
        private void dlKetPress()
        {
            string xdlh = StringUtil.ToDBC(this.dqdlhTxt.Text.Trim());
            //判断用户输入不为空，并且新的输入值不等于定义的全局变量
            if (!xdlh.Equals(ydl))
            {
                if (!string.IsNullOrEmpty(xdlh))
                {
                    List<string> list = StringUtil.getDlhs(xdlh);
                    List<string> list1 = StringUtil.getDlhs(ydl);
                    var srGorup1 = list.Where(x => !list1.Any(a => x.Trim() == a.Trim())).ToList();
                    using (DbOperHandler _open = new Common().Doh())
                    {
                        bool f = false;
                        string cdlh = string.Empty;
                        foreach (var a in srGorup1)
                        {
                            //Console.WriteLine("新登录号:" + a);
                            _open.Reset();
                            _open.ConditionExpress = "登录号='" + a + "' or 条形码='" + a + "'";
                            f = _open.Exist("馆藏典藏库");
                            if (flag)
                            {
                                cdlh = a;
                                break;
                            } 
                        }
                        if (!f)
                        {
                            _open.Reset();
                            _open.ConditionExpress = "登录号='" + xdlh + "'";
                            f = _open.Exist("采购库");
                            if (f)
                                cdlh = xdlh;
                        }
                       
                        if (flag)
                        {
                            ShowMessageBox.ShowMessageBoxTimeout("登录号【"+cdlh+"】重复，请重试", "警告", MessageBoxButtons.OK, 3000);
                        }
                        else
                        {
                            DataRowView current = this.CfData.Current as DataRowView;
                            string zjm = current["子键码"].ToString().Trim();
                            if (list1.Count > 0)
                            {
                                _open.Reset();
                                _open.ConditionExpress = "主键码=" + mainKay + " and (登录号='" + list1[0] + "' or 条形码='" + list1[0] + "')";
                                foreach (var a in srGorup1)
                                {
                                    //Console.WriteLine("新登录号:" + a);
                                    object[,] value = new object[12, 2] {
                                        {"主键码",this.mainKay},
                                        {"子键码",zjm},
                                        {"登录号",a},
                                        {"条形码",a},
                                        {"馆键码",1},
                                        {"馆藏地址",_open.GetField("馆藏典藏库","馆藏地址")},
                                        {"虚拟库室",_open.GetField("馆藏典藏库","虚拟库室")},
                                        {"处理日期",DateTime.Now},
                                        {"索书号",_open.GetField("馆藏典藏库","索书号")},
                                        {"操作员",this.uid},
                                        {"库键码",this.kjm},
                                        {"状态","G"}
                                        };
                                    _open.Reset();
                                    _open.AddFieldItems(value);
                                    _open.Insert("馆藏典藏库");
                                    _open.Reset();
                                    _open.ConditionExpress = "主键码=" + mainKay + " and 子键码=" + zjm+ " and 典藏员 is null";
                                    _open.AddFieldItem("典藏员", this.uid);
                                    _open.AddFieldItem("典藏分配日期", DateTime.Now);
                                    _open.AddFieldItem("入藏日期", DateTime.Now);
                                    _open.AddFieldItem("状态" ,"G");
                                    _open.Update("采购库");
                                }
                                var srGorup = list1.Where(x => !list.Any(a => x.Trim() == a.Trim())).ToList();
                                foreach (var a in srGorup)
                                {
                                    //Console.WriteLine("被删除登录号:" + a);
                                    _open.Reset();
                                    _open.ConditionExpress = "主键码=" + mainKay + " and (登录号='" + a + "' or 条形码='" + a + "')";
                                    _open.Delete("馆藏典藏库");
                                }
                            }
                            else
                            {
                                _open.Reset();
                                _open.ConditionExpress = "库键码=" + kjm;
                                string kfp = _open.GetField("书目数据库定义", "可用分配库室").ToString().Trim();
                                string[] kfps = kfp.Split(' ');
                                string sql = "select RTRIM(LTRIM(馆藏地址)) AS 馆藏地址,RTRIM(LTRIM(部门名称)) AS 馆藏地点 from 馆藏地址定义 where 虚拟库室=1 and 馆藏地址 in(";
                                for (int i = 0; i < kfps.Length; i++)
                                {
                                    sql = sql + "'" + kfps[i] + "',";
                                }
                                sql = sql.Substring(0, sql.Length - 1);
                                sql = sql + ")  order by 序号";
                                _open.Reset();
                                _open.SqlCmd = sql;
                                DataTable dt = _open.GetDataTable();
                                if (dt.Rows.Count > 0)
                                {
                                    _open.Reset();
                                    _open.ConditionExpress = "主键码=" + this.mainKay;
                                    var srGorup = list1.Where(x => !list.Any(a => x.Trim() == a.Trim())).ToList();
                                    foreach (var a in srGorup1)
                                    {
                                        //Console.WriteLine("新登录号1:" + a);
                                        object[,] value = new object[12, 2] {
                                        {"主键码",this.mainKay},
                                        {"子键码",zjm},
                                        {"登录号",a},
                                        {"条形码",a},
                                        {"馆键码",1},
                                        {"馆藏地址",dt.Rows[0]["馆藏地址"]},
                                        {"虚拟库室",1},
                                        {"处理日期",DateTime.Now},
                                        {"索书号",_open.GetField("馆藏书目库","索书号")},
                                        {"操作员",this.uid},
                                        {"库键码",this.kjm},
                                        {"状态","G"}
                                        };
                                        _open.Reset();
                                        _open.AddFieldItems(value);
                                        _open.Insert("馆藏典藏库");
                                        _open.Reset();
                                        _open.ConditionExpress = "主键码=" + mainKay + " and 子键码=" + zjm + " and 典藏员 is null";
                                        _open.AddFieldItem("典藏员", this.uid);
                                        _open.AddFieldItem("典藏分配日期", DateTime.Now);
                                        _open.AddFieldItem("入藏日期", DateTime.Now);
                                        _open.AddFieldItem("状态", "G");
                                        _open.Update("采购库");
                                    }
                                }
                                else
                                {
                                    ShowMessageBox.ShowMessageBoxTimeout("当前书目库无可分配馆藏地址！！", "警告", MessageBoxButtons.OK, 3000);
                                }
                            }
                            this.dqcsTxt.Text = list.Count.ToString();
                            _open.Reset();
                            _open.ConditionExpress = "主键码=" + mainKay + " and 子键码=" + zjm;
                            _open.AddFieldItem("册数", list.Count);
                            _open.AddFieldItem("登录号", this.dqdlhTxt.Text);
                            _open.AddFieldItem("验收员", this.uid);
                            _open.AddFieldItem("验收日期", DateTime.Now);
                            _open.Update("采购库");
                            _open.Reset();
                            _open.SqlCmd = "select 登录号,册数 from 采购库 where 主键码=" + mainKay;
                            DataTable cdl = _open.GetDataTable();
                            string dls = string.Empty;int cs = 0;
                            for(int i = 0; i < cdl.Rows.Count; i++)
                            {
                                if(!string.IsNullOrEmpty(cdl.Rows[i]["登录号"].ToString()))
                                    dls += cdl.Rows[i]["登录号"] + ";";
                                if(!string.IsNullOrEmpty(cdl.Rows[i]["册数"].ToString()))
                                    cs += Convert.ToInt32(cdl.Rows[i]["册数"]);
                            }
                            if (!string.IsNullOrEmpty(dls))
                            {
                                dls = dls.Substring(0, dls.Length - 1);
                                //Console.WriteLine(dls);
                                MarcConvert convert = new MarcConvert();
                                convert.MarcText= this.mTxt;
                                convert.ReplaceSubfield("905", "b", 1, dls);
                                convert.ReplaceSubfield("905", "f", 1, cs.ToString());
                                _open.Reset();
                                _open.ConditionExpress = "主键码=" + mainKay;
                                if (flag)
                                {
                                    _open.AddFieldItem("marc1", convert.MarcText);
                                    _open.Update("MARC_DATA");
                                }
                                else
                                {
                                    _open.AddFieldItem("marc", convert.MarcText);
                                    _open.Update("馆藏书目库");
                                }
                            }
                        }
                    }

                }
            }
            this.cxBtn.Enabled = false;
            this.sBtn.Enabled = false;
        }

        private void dc_EditingControlShowing(object sender, DataGridViewEditingControlShowingEventArgs e)
        {
            if (dataGridDc.CurrentCell.OwningColumn.Name.Equals("xnkss") && e.Control is ComboBox)
            {
                (e.Control as ComboBox).SelectedValueChanged += new EventHandler(ComboBox_SelectedValueChanged);
            }
            if (dataGridDc.CurrentCell.OwningColumn.Name.Equals("scks") && e.Control is ComboBox)
            {
                (e.Control as ComboBox).SelectedValueChanged += new EventHandler(ScBox_SelectedValueChanged);
            }
        }
        private void DgvGcbox()
        {
            using (DbOperHandler _open = new Common().Doh())
            {
                if (dataGridDc.CurrentCell != null)
                {
                    string sck = dataGridDc.CurrentRow.Cells["xnkss"].Value.ToString().Trim();
                    _open.Reset();
                    _open.ConditionExpress = "库室名称='" + sck + "'";
                    this.xzid = Convert.ToInt32(_open.GetField("虚拟库室", "虚拟库室").ToString());
                }
                _open.Reset();
                _open.ConditionExpress = "库键码=" + kjm;
                string kfp = _open.GetField("书目数据库定义", "可用分配库室").ToString().Trim();
                string[] kfps = kfp.Split(' ');
                string sql = "select RTRIM(LTRIM(馆藏地址)) AS 馆藏地址,RTRIM(LTRIM(部门名称)) AS 馆藏地点 from 馆藏地址定义 where  馆藏地址 in(";
                for (int i = 0; i < kfps.Length; i++)
                {
                    sql = sql + "'" + kfps[i] + "',";
                }
                sql = sql.Substring(0, sql.Length - 1);
                sql = sql + ")";
                //if(this.xzid>0)
                //   sql = sql + " and 虚拟库室=" + xzid ;
                sql = sql + " order by 序号";
                //Console.WriteLine(sql);
                _open.Reset();
                _open.SqlCmd = sql;
                this.gcd.Clear();
                DataTable dt = _open.GetDataTable();
                this.scks.DataSource = dt;
                this.scks.DisplayMember = "馆藏地点";
                this.scks.ValueMember = "馆藏地点";
                this.scks.DataPropertyName = "馆藏地点";
                this.scks.ValueType = typeof(Int32);
            }
        }

        private void ScBox_SelectedValueChanged(object sender, EventArgs e)
        {
            ComboBox combox = sender as ComboBox;
            //添加离开combox的事件
            combox.Leave += new EventHandler(scbox_Leave);
            if (combox.SelectedItem != null && dataGridDc.CurrentCell.ColumnIndex == 2) //在Rename栏中选中organname后
            {
                DataRowView current = this.DcData.Current as DataRowView;
                string kay = current["子键码"].ToString().Trim();
                string dlh = dataGridDc.CurrentRow.Cells["dlh"].Value.ToString().Trim();
                using (DbOperHandler _open = new Common().Doh())
                {
                    string sck = combox.Text.Trim();
                    _open.Reset();
                    _open.ConditionExpress = "部门名称='" + sck + "'";
                    xzgcd = _open.GetField("馆藏地址定义", "馆藏地址").ToString().Trim();
                    //Console.WriteLine(string.Format("选中:{0},{1}", combox.Text, combox.SelectedIndex) + ":" + xzgcd + ":" + dlh + ":" + this.xzid +":" + kay);
                    if (!string.IsNullOrEmpty(xzgcd))
                    {
                        _open.Reset();
                        _open.ConditionExpress = "子键码=" + kay + " and 登录号='" + dlh + "' ";
                        _open.AddFieldItem("馆藏地址", xzgcd);
                        int m = _open.Update("馆藏典藏库");
                    }
                }
            }
        }
        private void ComboBox_SelectedValueChanged(object sender, EventArgs e)
        {
            DataRowView current = this.DcData.Current as DataRowView;
            string kay = current["子键码"].ToString().Trim();
            string dlh = dataGridDc.CurrentRow.Cells["dlh"].Value.ToString().Trim();
            ComboBox combox = sender as ComboBox;
            //添加离开combox的事件
            combox.Leave += new EventHandler(combox_Leave);
            int n = dataGridDc.CurrentCell.RowIndex;
            DataGridViewComboBoxCell ReOrganNames = (DataGridViewComboBoxCell)dataGridDc.Rows[n].Cells["scks"];
            if (combox.SelectedItem != null && !combox.Text.Equals("System.Data.DataRowView")  && dataGridDc.CurrentCell.ColumnIndex == 1)
            {
                ReOrganNames.ReadOnly = false;
                ReOrganNames.DataSource = null;
                int k = combox.SelectedIndex;
                this.xzid = kid[k];
                //Console.WriteLine(string.Format("选中:{0},{1}", combox.Text, this.xzid));
                using (DbOperHandler _open = new Common().Doh())
                {
                    _open.Reset();
                    _open.ConditionExpress = "库键码=" + kjm;
                    string kfp = _open.GetField("书目数据库定义", "可用分配库室").ToString().Trim();
                    string[] kfps = kfp.Split(' ');
                    string sql = "select RTRIM(LTRIM(馆藏地址)) AS 馆藏地址,RTRIM(LTRIM(部门名称)) AS 馆藏地点 from 馆藏地址定义 where 虚拟库室=" + xzid + " and 馆藏地址 in(";
                    for (int i = 0; i < kfps.Length; i++)
                    {
                        sql = sql + "'" + kfps[i] + "',";
                    }
                    sql = sql.Substring(0, sql.Length - 1);
                    sql = sql + ")  order by 序号";
                    _open.Reset();
                    _open.SqlCmd = sql;
                    this.gcd.Clear();
                    DataTable dt = _open.GetDataTable();
                    ReOrganNames.Items.Clear();
                    foreach (DataRow dRow in dt.Rows)
                    {
                        ReOrganNames.Items.Add(dRow["馆藏地点"].ToString().Trim());
                        this.gcd.Add(dRow["馆藏地址"].ToString().Trim());
                    }
                    if (xzid > 0)
                    {
                        _open.Reset();
                        _open.ConditionExpress = "子键码=" + kay + " and 登录号='" + dlh + "' ";
                        if(this.gcd.Count>0)
                            _open.AddFieldItem("馆藏地址", this.gcd[0]);
                        _open.AddFieldItem("虚拟库室", xzid);
                        _open.Update("馆藏典藏库");
                    }
                }
            }
            
        }
        public void combox_Leave(object sender, EventArgs e)
        {
            ComboBox combox = sender as ComboBox;
            //做完处理，须撤销动态事件
            combox.SelectedIndexChanged -= new EventHandler(ComboBox_SelectedValueChanged);
        }
        public void scbox_Leave(object sender, EventArgs e)
        {
            ComboBox combox = sender as ComboBox;
            //做完处理，须撤销动态事件
            combox.SelectedIndexChanged -= new EventHandler(ScBox_SelectedValueChanged);
        }
        /// <summary>
        /// 下拉点击1次触发
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void dc_CellEnter(object sender, DataGridViewCellEventArgs e)
        {
            if (e.ColumnIndex >= 0 && e.RowIndex >= 0 && dataGridDc[e.ColumnIndex, e.RowIndex] != null && !dataGridDc[e.ColumnIndex, e.RowIndex].ReadOnly)
            {
                DataGridViewComboBoxColumn comboBoxColumn = dataGridDc.Columns[e.ColumnIndex] as DataGridViewComboBoxColumn;
                if (comboBoxColumn != null)
                {
                    this.dataGridDc.CurrentCell = dataGridDc[e.ColumnIndex, e.RowIndex];
                    dataGridDc.BeginEdit(true);
                    DataGridViewComboBoxEditingControl comboBoxEditingControl = dataGridDc.EditingControl as DataGridViewComboBoxEditingControl;
                    if (comboBoxEditingControl != null)
                    {
                        comboBoxEditingControl.DroppedDown = true;
                    }
                }
            }
        }

        private void dataGridCg_CellClick(object sender, DataGridViewCellEventArgs e)
        {
            if(e.RowIndex != -1)
                if (e != null)
                    this.dataGridCg.Rows[e.RowIndex].Selected = true;
        }

        private void dj_MouseLeave(object sender, EventArgs e)
        {
            string xdj = StringUtil.ToDBC(this.dqdjTxt.Text.Trim());
            //判断用户输入不为空，并且新的输入值不等于定义的全局变量
            if (!xdj.Equals(ydj))
            {
                try
                {
                    double.Parse(xdj);
                    this.cxBtn.Enabled = true;
                    this.sBtn.Enabled = true;
                }
                catch {
                    MessageBox.Show("输入内容不合法");
                    this.cxBtn.Enabled = false;
                    this.sBtn.Enabled = false;
                }
            }
            else
            {
                this.cxBtn.Enabled = false;
                this.sBtn.Enabled = false;
            }
        }

        private void dj_KeyPress(object sender, KeyPressEventArgs e)
        {
            if (e.KeyChar == '\r')
            {
                this.djKeyPress();
                this.BookData_PositionChanged(sender, e);
            }
        }
        private void dudMaxThreads_ValueChanged(object sender, EventArgs e)
        {
            ThreadPool.SetMaxThreads((int)this.dudMaxThreads.Value, (int)this.dudMaxThreads.Value);
        }

        private void djKeyPress()
        {
            string xdj = StringUtil.ToDBC(this.dqdjTxt.Text.Trim());
            //判断用户输入不为空，并且新的输入值不等于定义的全局变量
            if (!xdj.Equals(ydj))
            {
                try
                {
                    double dj = double.Parse(xdj);
                    string cs = this.dqcsTxt.Text.Trim();
                    double je = dj * Convert.ToInt32(cs);
                    DataRowView current = this.CfData.Current as DataRowView;
                    string zjm = current["子键码"].ToString().Trim();
                    using (DbOperHandler _open = new Common().Doh())
                    {
                        _open.Reset();
                        _open.ConditionExpress = "主键码=" + mainKay + " and 子键码=" + zjm;
                        _open.AddFieldItem("订购单价", dj);
                        _open.AddFieldItem("单价", dj);
                        _open.AddFieldItem("订购金额", je);
                        _open.AddFieldItem("金额", je);
                        _open.Update("采购库");
                    }
                }
                catch
                { }
            }

        }

        private void autoCHunk_CheckedChanged(object sender, EventArgs e)
        {
            CheckBox checkBox = sender as CheckBox;
            if (checkBox.Checked)
            {
                this.dudChunkSize.Enabled = false;
            }
            else
            {
                this.dudChunkSize.Enabled = true;
            }
        }
        private void chkLogin_CheckedChanged(object sender, EventArgs e)
        {
            CheckBox checkBox = sender as CheckBox;
            if (checkBox.Checked)
            {
                this.txtUsername.Enabled = true;
                this.txtPassword.Enabled = true;
            }
            else
            {
                this.txtUsername.Enabled = false;
                this.txtPassword.Enabled = false;
            }
        }

        private void workerGetFileList_DoWork(object sender, DoWorkEventArgs e)
        {
            bool f = this.AuthenticateWebService();
            if (f)
            {
                string[] filesList = WebService.GetFilesList();
                e.Result = filesList;
            }
            else
            {
                e.Cancel = true;
            }
        }
        private void workerGetFileList_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
        {
            if (e.Cancelled)
            {
                this.lblErrors.Text = "MTOM服务端连接失败";
                this.mtomRadio.Enabled = false;
            }
            else
            {
                if (e.Error != null)
                {
                    this.mtomRadio.Enabled = false;
                    if (e.Error.Message.Contains("ReturnUrl=") || e.Error.Message.Contains("forcibly closed"))
                    {
                        this.lblErrors.Text = "Forms Authentication Required";
                        this.chkLoginRequired.Checked = true;
                        this.txtUsername.Focus();
                    }
                    else
                    {
                        this.lblErrors.Text = "Could not list files on server: " + e.Error.Message;
                    }
                }
                else
                {
                    this.mtomRadio.Enabled = true;
                    this.lblErrors.Text = "";
                    this.lstDownloadFiles.Items.Clear();
                    foreach (string str in e.Result as string[])
                    {
                        this.lstDownloadFiles.Items.Add(str);
                    }
                }
            }

        }

        private void workerFTP_DoWork(object sender, DoWorkEventArgs e)
        {
            ftpFull = FileTool.CheckFTP(DbConfig.FtpAddress, DbConfig.FtpUser, DbConfig.FtpPass, Convert.ToInt32(DbConfig.FtpPort));
            if (!ftpFull)
            {
                this.ftpRadio.Enabled = false;
                e.Cancel = true;
            }
            else
            {
                this.ftpRadio.Enabled = true;
            }

        }

        private void workerFTP_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
        {
            if (e.Cancelled)
            {
                this.lblErrors.Text = "FTP服务端连接失败";
            }
            else
                this.lblErrors.Text = "";
        }

        private void excelItem_Click(object sender, EventArgs e)
        {
            this.kjm = this.baseSearch1._kjm;
            FrmGcExcelImp fr = new FrmGcExcelImp();
            fr.kjm = this.kjm;
            if (fr.ShowDialog() == DialogResult.OK)
            {

            }

        }

        private void allisoItem_Click(object sender, EventArgs e)
        {

        }

        private void dqupItem_Click(object sender, EventArgs e)
        {

        }

        private void plupFiles(string kay,string FilePath)
        {
            if (usType == 0)
            {
                this.AddFileUpLoad(FilePath, kay);
            }
            if (usType == 1)
            {
                this.up = new UploadFiles(this.uid, this.Name);
                string kzName = Path.GetExtension(FilePath).ToLower();
                string fileName = Path.GetFileName(FilePath);
                string eFileName = string.Empty;
                if (this.gfnCheck.Checked)
                    eFileName = StringSecurity.Encrypt(DateTime.Now.ToString("yyyyMMddhhmmss")) +  kzName;
                else
                    eFileName = StringSecurity.Encrypt(fileName)  + kzName;
                string eFile = DbConfig.WorkDir + eFileName;
                FileTool.CopyAndDeleteFile(FilePath, eFile);
                this.up.AddFileUpLoad("0", eFile, kay);
            }
            if (usType == 2)
            {
                this.BduploadFiles(kay, FilePath);
            }
        }
        /// <summary>
        /// 将文件更名后存储本地
        /// </summary>
        /// <param name="kay">主键码</param>
        /// <param name="FilePath">源文件路径</param>
        private void BduploadFiles(string kay,string FilePath)
        {
            string guid = Guid.NewGuid().ToString();
            string kzName = Path.GetExtension(FilePath).ToUpper().Replace(".", "");
            string fileName = Path.GetFileName(FilePath);
            string eFileName = string.Empty;
            if(this.gfnCheck.Checked)
                eFileName = StringSecurity.Encrypt(DateTime.Now.ToString("yyyyMMddhhmmss")) + "." + kzName.ToLower();
            else
                eFileName = StringSecurity.Encrypt(fileName)+ "." + kzName.ToLower();
            string eFile = DbConfig.WorkDir + eFileName;
            FileTool.CopyFile(FilePath, eFile);
            //Console.WriteLine(":::"+kay + ":" + eFileName + ":" + guid);
            if (FileFunction.InsertInfor("0", kay, kzName, eFileName, this.uid, FilePath, guid))
            {
                //Console.WriteLine(kay + ":" + eFileName + ":" + guid);
                ControlLog.AddUpLoadLog("0",this.uid, fileName, kay);
                if (!FileFunction.UpdateSucess("0", guid, this.uid))
                {
                    MessageBox.Show("更新上传库信息失败！", "提示", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                }
                else if (DbConfig.DelOnUpLoadSucess == "1")
                {
                    DeleteFile file = new DeleteFile(guid, "0");
                    new Thread(new ThreadStart(file.DoWork)).Start();
                }
            }
        }
        private void allupItem_Click(object sender, EventArgs e)
        {
            this.MarcRadio();
            List<string> keys = new List<string>();
            List<string> fileds = new List<string>();
            FrmUpFileds fr = new FrmUpFileds();
            fr.fileds = this.baseSearch1.FiledsList;
            if (fr.ShowDialog() == DialogResult.OK)
            {
                for (int i = 0; i < this.dataGridBook.Rows.Count; i++)
                {
                    try
                    {
                        string kay = this.dataGridBook.Rows[i].Cells["主键码"].Value.ToString().Trim();
                        keys.Add(kay);
                        string filedName = this.dataGridBook.Rows[i].Cells[fr.rtxt].Value.ToString().Trim();
                        fileds.Add(filedName);
                    }catch(Exception ex)
                    {
                        Console.WriteLine(ex.Message);
                    }
                }
                using (DbOperHandler _open = new Common().Doh())
                {
                    if (this.folderBrowser.ShowDialog() == DialogResult.OK)
                    {
                        foreach (System.Windows.Forms.Control control in this.Controls)
                        {
                            if(!(control is DevComponents.DotNetBar.ExpandablePanel))
                                control.Enabled = false;
                        }
                        string path = this.folderBrowser.SelectedPath;
                        DirectoryInfo dirInfo = new DirectoryInfo(path);
                        FileInfo[] files = dirInfo.GetFiles();
                        FrmUpProgess progess = new FrmUpProgess();
                        progess.ShowInTaskbar = false;
                        progess.Owner = this;
                        progess.Show();
                        progess.progressBarX1.Maximum = files.Length;
                        int num = 0;
                        foreach (FileInfo file in files)
                        {
                            num++;
                            Application.DoEvents();
                            progess.label1.Text = "当前文件:" + file.FullName;
                            progess.progressBarX1.Value = num;
                            string fileName = file.Name.Split('.')[0];
                            string kzm = file.Name.Split('.')[1].ToUpper() ;
                            int index = fileds.IndexOf(fileName);
                            //Console.WriteLine(fileName + "::"+index+"::"+fileds.Count);
                            if (index >= 0)
                            {
                                string zjm = keys[index];
                                bool f = false;
                                if (!this.cfCheck.Checked)
                                {
                                    _open.Reset();
                                    _open.ConditionExpress = "主键码=" + zjm + " and 完成状态=1 and 扩展名='" + kzm + "'";
                                    f = _open.Exist("Disk_文件信息表");
                                    //Console.WriteLine(file.FullName + ":" + zjm);
                                    /**
                                    if (!f)
                                    {
                                        _open.Reset();
                                        _open.SqlCmd = "select 登录号 from 馆藏典藏库 where 主键码=" + zjm;
                                        DataTable dr = _open.GetDataTable();
                                        if (dr.Rows.Count > 0)
                                        {
                                            foreach (DataRow drow in dr.Rows)
                                            {
                                                _open.Reset();
                                                _open.ConditionExpress = "登录号='" + drow["登录号"] + "'";
                                                f = _open.Exist("Disk_复本文件信息表");
                                                if (f)
                                                    break;
                                            }
                                        }
                                    }
                                    **/
                                    if (!f)
                                    {
                                        //Console.WriteLine("开始处理:"+file.FullName + ":" + zjm);
                                        this.plupFiles(zjm, file.FullName);
                                        //Console.WriteLine(StringSecurity.Encrypt(fileName));
                                        //Console.WriteLine(StringSecurity.Decrypt(StringSecurity.Encrypt(fileName)));
                                        //Console.WriteLine(StringSecurity.GetMd5(fileName));
                                        //Console.WriteLine(StringSecurity.StringToSHA1Hash(fileName));
                                    }
                                }
                                else
                                {
                                    this.plupFiles(zjm, file.FullName);
                                }
                            }
                        }
                        progess.Close();
                    }
                }
            }
            
        }

        private void dqisoItem_Click(object sender, EventArgs e)
        {

        }

        private void dquisoItem_Click(object sender, EventArgs e)
        {

        }
        public void AddFileUpLoad(string FilePath, string MainKay)
        {
            string guid = Guid.NewGuid().ToString();
            string kzName = Path.GetExtension(FilePath).ToUpper().Replace(".", "");
            string fileName = Path.GetFileName(FilePath);
            string eFileName = string.Empty;
            if (this.gfnCheck.Checked)
                eFileName = StringSecurity.Encrypt(DateTime.Now.ToString("yyyyMMddhhmmss")) + "." + kzName.ToLower();
            else
                eFileName = StringSecurity.Encrypt(fileName) + "." + kzName.ToLower();
            string eFile = DbConfig.WorkDir + eFileName;
            FileTool.CopyAndDeleteFile(FilePath, eFile);
            //ControlLog.AddCreateISOLog(this.uid, fileName, MainKay);
            if (FileFunction.InsertInfor("0", MainKay, kzName, eFileName, this.uid, eFile, guid))
            {
                this.taskPanel1.AddOperation(new TaskPanelOperation(guid, $"上传: {Path.GetFileName(eFile)}", ProgressBarStyle.Blocks));
                ThreadPool.QueueUserWorkItem(new WaitCallback(this.MtomUpFile), new Triplet(guid, eFile, 0));
                ControlLog.AddUpLoadLog("0", this.uid, eFileName, MainKay);
            }
        }
        private void MtomUpFile(object triplet)
        {
            string str = (triplet as Triplet).First.ToString();
            string str2 = (triplet as Triplet).Second.ToString();
            long argument = long.Parse((triplet as Triplet).Third.ToString());
            FileTransferUpload upload = new FileTransferUpload();
            upload.WebService.CookieContainer = WebService.CookieContainer;
            upload.Guid = str;
            if (this.chkAutoChunksize.Checked)
            {
                upload.AutoSetChunkSize = true;
            }
            else
            {
                upload.AutoSetChunkSize = false;
                upload.ChunkSize = ((int)this.dudChunkSize.Value) * 0x400;
            }
            upload.LocalFilePath = str2;
            upload.IncludeHashVerification = this.chkHash.Checked;
            upload.ProgressChanged += new ProgressChangedEventHandler(this.ft_ProgressChanged);
            upload.RunWorkerCompleted += new RunWorkerCompletedEventHandler(this.ft_RunWorkerCompleted);
            upload.RunWorkerSync(new DoWorkEventArgs(argument));
        }
        private void ft_ProgressChanged(object sender, ProgressChangedEventArgs e)
        {
            this.taskPanel1.ProgressChanged((sender as FileTransferBase).Guid, e.ProgressPercentage, e.UserState.ToString());
        }
        private void ft_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
        {
            string guid = (sender as FileTransferBase).Guid;
            if (e.Error != null)
            {
                this.taskPanel1.EndOperation(guid, e.Error);
            }
            else if (e.Cancelled)
            {
                this.taskPanel1.EndOperation(guid, new Exception("Cancelled"));
            }
            else
            {
                this.taskPanel1.EndOperation(guid, null);
                if (this.taskPanel1.List.Count == 0)
                {
                    this.Ding();
                }
                if (!FileFunction.UpdateSucess("0", guid, this.uid))
                {
                    MessageBox.Show("更新上传库信息失败！", "提示", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                }
                else if (DbConfig.DelOnUpLoadSucess == "1")
                {
                    DeleteFile file = new DeleteFile(guid, "0");
                    new Thread(new ThreadStart(file.DoWork)).Start();
                }
            }
        }
        private void Ding()
        {
            try
            {
                SoundPlayer player = new SoundPlayer();
                player.SoundLocation = "download_complete.wav"; //把wav音频文件放在exe同目录下就行
                player.Load();//加载
                player.PlaySync();//阻塞进程，播放完毕后才会执行后面的代码
                Invoke(new Action(() =>
                {
                    foreach (System.Windows.Forms.Control control in this.Controls)
                    {
                        control.Enabled = true;
                    }
                }));
            }
            catch
            {
                Invoke(new Action(() =>
                {
                    foreach (System.Windows.Forms.Control control in this.Controls)
                    {
                        control.Enabled = true;
                    }
                }));
            }
        }

        private void toolStripButton1_Click(object sender, EventArgs e)
        {
            using (DbOperHandler _open = new Common().Doh())
            {
                int size = this.dataGridBook.Rows.Count;
                for (int i = 0; i < this.dataGridBook.Rows.Count; i++)
                {
                    string kay = this.dataGridBook.Rows[i].Cells["主键码"].Value.ToString().Trim();
                    _open.Reset();
                    _open.ConditionExpress = "主键码=" + kay;
                    string marc = _open.GetField("馆藏书目库", "marc").ToString();
                    MarcConvert convert = new MarcConvert();
                    convert.MarcText = marc;
                    string pdate = convert.GetASubField("210", "d", 1);
                    if (!string.IsNullOrEmpty(pdate))
                    {
                        pdate = StringUtil.ToDBC(pdate).Replace(@"'", "\'");
                        _open.AddFieldItem("出版日期", pdate);
                    }
                    else
                    {
                        pdate = DateTime.Now.Year.ToString();
                    }
                    double dj = 5.00;
                    string xgh = convert.GetASubField("701", "d", 1);
                    if (!string.IsNullOrEmpty(xgh))
                    {
                        xgh = StringUtil.ToDBC(xgh).Replace(@"'", "\'").Replace("?","");
                        _open.Reset();
                        _open.ConditionExpress = "主键码=" + kay;
                        int dzjm = (int)_open.GetField("采购库", "子键码");
                        _open.Reset();
                        _open.ConditionExpress = "子键码=" + dzjm;
                        if (!_open.Exist("馆藏典藏库"))
                        {
                            try
                            {
                                _open.Reset();
                                _open.ConditionExpress = "主键码=" + kay;
                                _open.Reset();
                                _open.AddFieldItem("子键码", dzjm);
                                _open.AddFieldItem("主键码", kay);
                                _open.AddFieldItem("库键码", 12);
                                _open.AddFieldItem("馆键码", 1);
                                _open.AddFieldItem("登录号", xgh);
                                _open.AddFieldItem("条形码", xgh);
                                _open.AddFieldItem("馆藏地址", "B");
                                _open.AddFieldItem("虚拟库室", 2);
                                _open.AddFieldItem("操作员", 1);
                                _open.AddFieldItem("状态", "G");
                                _open.AddFieldItem("刊价", dj);
                                string ssh = convert.GetASubField("690", "a", 1);
                                if (!string.IsNullOrEmpty(ssh))
                                    _open.AddFieldItem("索书号", ssh);
                                _open.AddFieldItem("处理日期", DateTool.stringToDate(pdate + "-09-20", DateTool.formatDate2));
                                _open.Insert("馆藏典藏库");
                            }
                            catch (OleDbException ex)
                            {
                                //Console.WriteLine(xgh + ":" + ex.Message);
                                LogManager.WriteLog("典藏出错", xgh + ":" + ex.Message);
                            }
                        }                        
                    }                   
                }
            }
        }
    }
}
